package com.web.webtitle.controller;

import com.web.webtitle.service.TitleHotService;
import com.web.webtitle.vo.Query;
import com.web.webtitle.vo.TitleHotCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
@CrossOrigin
@RestController //返回数据、视图
@RequestMapping("/home") //追加上下文路径
public class HomeController {
    @Autowired
    private TitleHotService hotService;


    @PostMapping("/count")
    public List<TitleHotCount> count(@RequestBody Query query) throws IOException {
        return hotService.countByAgentAndTimeStamp( query.getAgent(), query.getStart(), query.getEnd());
    }

    /**
     * 分别统计标题的热度
     * @return
     * @throws IOException
     */
    @RequestMapping("/hotsgroup")
    public List<TitleHotCount> hotsgroup() throws IOException {
        return hotService.findTitleCountByTimeStamp(0,System.currentTimeMillis());
    }
}
